<?php

class Area_Model extends Model
{
	//campos da entidade Area
	private $cod_area;
	private $nome_area;
	private $sqlInsert = "INSERT INTO area (nome_area) VALUES ('%s')";
	private $sqlDelete = "DELETE FROM area WHERE cod_area='%s'";
	private $sqlUpdate = "UPDATE area SET nome_area='%s' WHERE cod_area='%s' ";
	private $sqlSelect = "SELECT * FROM area WHERE 1=1 %s %s";
	
	public function setCodArea($codigo)
	{
		$this->cod_area = trim(strip_tags(mysql_real_escape_string($codigo)));	
	}
	
	public function setNomeArea($nome)
	{
		$this->nome_area = trim(strip_tags(mysql_real_escape_string($nome)));	
	}
	
	public function getCodArea()
	{
		return $this->cod_area;	
	}
	
	public function getNomeArea()
	{
		return $this->nome_area;	
	}
	
	public function insert()
	{
		$sql = sprintf($this->sqlInsert,$this->getNomeArea());
		return $this->runQuery($sql);	
	}
	
	public function update()
	{
		$sql = sprintf($this->sqlUpdate,$this->getNomeArea(),$this->getCodArea());
		return $this->runQuery($sql);	
	}
	
	public function delete()
	{
		$sql = sprintf($this->sqlDelete,$this->getCodArea());
		return $this->runQuery($sql);	
	}
	
	public function select($where='',$order='')
	{
		$sql = sprintf($this->sqlSelect,$where,$order);
		return $this->runSelect($sql);	
	}
	
	public function load()
	{
		$where = sprintf("AND cod_area='%s'",$this->getCodArea());
		$row = $this->select($where); 	
		$this->setCodArea($row[0]['cod_area']);
		$this->setNomeArea($row[0]['nome_area']);
		return $this;
	}
		
}